package com.core.gui.components;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

public class PlaceComboBoxModel<T> extends AbstractListModel implements
		ComboBoxModel {

	private static final long serialVersionUID = 1L;

	private List<T> places = new ArrayList<>();

	T selection = null;

	public List<T> getPlaces() {
		return places;
	}

	public void setPlaces(List<T> places) {
		this.places = places;
	}

	@Override
	public int getSize() {
		return places.size();
	}

	@Override
	public T getElementAt(int index) {
		return places.get(index);
	}

	@Override
	public void addListDataListener(ListDataListener l) {
		listenerList.add(ListDataListener.class, l);
	}

	@Override
	public void removeListDataListener(ListDataListener l) {
		listenerList.remove(ListDataListener.class, l);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void setSelectedItem(Object anItem) {
		selection = (T) anItem;
	}

	@Override
	public Object getSelectedItem() {
		return selection;
	}

	public void clear() {
		places.clear();
		selection = null;
	}

	// public T getselectionPlace() {
	// return selection;
	// }

}
